#include "MsgError.h"
#include "BasicTypes.h"

using namespace std;

string MsgError::Message() const
{
	string errMsg;
	switch (m_ErrorCode)
	{
	case ERR_UNKNOWN_DECODE_FORMAT:
		errMsg = "Unknown decoded message format";
		break;
	case ERR_DECODE_FORMAT_NOT_SET:
		errMsg = "Decode format not set";
		break;
	case ERR_UNKNOWN_PROTOCOL:
		errMsg = "Unknown protocol";
		break;
	case ERR_UNKNOWN_FILTER_TYPE:
		errMsg = "Unknown filter type";
		break;
	case ERR_INVALID_FILTER:
		errMsg = "Filter is invalid";
		break;
	case ERR_FILTER_NOT_SET:
		errMsg = "Filter not set";
		break;
	case ERR_INTERNAL_ERROR:
		errMsg = "Internal error";
		break;
	default:
		errMsg = "Unknown error";
	}
	string errData;
	if (m_errData.get())
		errData = m_errData->Serialize();
	unsigned int header = (unsigned int)MT_ERROR;
	header += 256 * (1 + (unsigned int)errMsg.length() + 1 + (unsigned int)errData.length());
	string message( (char *)&header, 4 );
	message += (char)m_ErrorCode;
	message += errMsg;
	message += (char)0;
	message += errData;
	return message;
}